package run.siyuan.manag.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import run.siyuan.manag.entity.SysMenu;
import run.siyuan.manag.entity.SysUser;
import run.siyuan.manag.entity.vo.SysUserVo;
import run.siyuan.manag.mapper.SysUserMapper;
import run.siyuan.manag.service.SysMenuService;
import run.siyuan.manag.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author siyuan
 * @since 2021-01-13
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private SysMenuService sysMenuService;

    @Override
    public Set<String> findPermissions(String name) {
        Set<String> setColls = new HashSet<>();
        List<SysMenu> menuList = sysMenuService.findByUser(name);
        for (SysMenu sysMenu : menuList) {
            if (StrUtil.isNotBlank(sysMenu.getPerms())){
                setColls.add(sysMenu.getPerms());
            }
        }
        return setColls;
    }
}
